<?php
namespace app\common\model;

use think\Model;
use think\Db;

/**
 * 
 */
class Search extends Model
{

    protected $table = 'sinblog_contents';

    /*
     * 根据关键字搜索文章
     * 可匹配的关键字类型：作者，标题，内容，标签，分类，时间
     */
	function getArticles($pointStr){
        $res = $this->query("select * from {$this->table} where title like '%{$pointStr}%'");
        if (!$res) {
            return "没有结果";
        }

        for ($i=0; $i < count($res); $i++) { 
            $title = $res[$i]['title'];
            $text = $res[$i]['text'];
            $res[$i]['title'] = str_replace($pointStr, "<span style='color:red;'>{$pointStr}</span>",$title);
            $res[$i]['text'] = str_replace($pointStr, "<span style='color:red;'>{$pointStr}</span>",$text);
        }
        return $res;
	}
}
